package com.wish.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.base.entity.Business;
import com.wish.base.entity.SysUser;
import com.wish.base.mapper.BusinessMapper;
import com.wish.base.service.IBusinessService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wish.base.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 商户表 服务实现类
 * </p>
 *
 * @author group02
 * @since 2022-05-23
 */
@Service
public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business> implements IBusinessService {


    @Autowired
    ISysUserService sysUserService;

    @Override
    public void addBusiness(Business business) {
        SysUser sysUser = sysUserService.getOne(new QueryWrapper<SysUser>().eq("mobile", business.getMobile()));

        //完善用户信息
        sysUser.setContactMember(business.getCorporation());
        sysUser.setProvince(business.getProvince()+"");
        sysUser.setCity(business.getCity()+"");
        sysUser.setCountry(business.getCounty()+"");
        sysUser.setCompanyName(business.getName());
        sysUserService.saveOrUpdate(sysUser);

        //增加商户表
        business.setUserId(Integer.parseInt(sysUser.getUserId()+""));
        business.setCreateTime(new Date());
        business.setStatus(3);
        save(business);
    }

}
